# Colorful China map

library(maptools)
china2 <- readShapePoly("./China_Province/map.shp")

# Chinese provinces' name
# provname = c("北京市","天津市","河北省","山西省","内蒙古自治区",
#            "辽宁省","吉林省","黑龙江省","上海市","江苏省",
#            "浙江省","安徽省","福建省","江西省","山东省",
#            "河南省","湖北省","湖南省","广东省",
#            "广西壮族自治区","海南省","重庆市","四川省","贵州省",
#            "云南省","西藏自治区","陕西省","甘肃省","青海省",
#            "宁夏回族自治区","新疆维吾尔自治区","台湾省",
#            "香港特别行政区");

provname = c("Anhui", "Beijing", "Chongqing", "Fujian", "Gansu", "Guangdong",
             "Guangxi", "Guizhou", "Hainan", "Hebei", "Heilongjiang", "Henan",
             "Hubei", "Hunan", "Jiangsu", "Jiangxi", "Jilin", "Liaoning",
             "Nei Mongol", "Ningxia Hui", "Paracel Islands", "Qinghai", 
             "Shaanxi", "Shandong", "Shanghai", "Shanxi", "Sichuan", "Tianjin",
             "Xinjiang Uygur", "Xizang", "Yunnan", "Zhejiang");

provname = c("Beijing", "Tianjin", "Hebei", "Shanxi", "Nei Mongol",
           "Liaoning", "Jilin", "Helongjiang", "Shanghai", "Jiangsu",
           "Zhejiang", "Anhui", "Fujian","Jiangxi","Shandong",
           "Henan","Hubei","Hunan","Guangdong",
           "Guangxi","Hainan","Chongqing","Sichuan","Guizhou",
           "Yunnan","Xizang","Shaanxi","Gansu","Qinghai",
           "Ningxia Hui","Xinjiang Uygur")

# Population of every provinces
population = c(1633,1115,6943,3393,2405,4298,2730,3824,1858,7625,
             5060,6118,3581,4368,9367,9360,5699,6355,9449,
             4768,845,2816,8127,3762,4514,284,3748,2617,
             552,610,2095)

# Create the color vector by popultion
provcol = rgb(red = 0,
              green = 1 - population/max(population)/2,
              blue = 1 - population/max(population)/2);

# Make map color
mapcolor = rep(0, 925)
for (idx in 1:33) {
  mapcolor[china2@data$NAME == provname[idx]] <- provcol[idx]
}

plot(china2, col = mapcolor, xlab = "",ylab = "")

